package hesso.smartdraw.ch.guielements;

import hesso.smartdraw.ch.DrawWallScreen;

import java.util.ArrayList;

import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class LevelSwitcher {
	
	private Scene scene;
	
	private int posX;
	private int posY;
	
	private ArrayList<Level> surLevels;
	private ArrayList<Level> subLevels;
	
	private Level basement;
	
	private Rectangle ground;
	
	private LevelAddHandler surButton;
	private LevelAddHandler subButton;
	
	public LevelSwitcher(Scene scene, int posX, int posY, ArrayList<Level> surLevels,  ArrayList<Level> subLevels,
			TextureRegion up, TextureRegion upMin, TextureRegion down, TextureRegion downMin, TextureRegion level,
			DrawWallScreen dw) {
		
		
		this.scene = scene;
		
		this.posX = posX -100;
		this.posY = posY -150;
		
		if(surLevels == null) {
				// SHALL NEVER HAPPEN! lol
			basement = new Level(this.posX, this.posY, level, 0, null, false);
			//basement.setColor(Color.RED);
			
			this.surLevels = new ArrayList<Level>();
			this.surLevels.add(basement);
			scene.attachChild(basement);
			scene.registerTouchArea(basement);
			
		} else {						
			for(int i = 0; i < surLevels.size(); i++){
				surLevels.get(i).setPosition(this.posX, this.posY - (i * 32.0f));
				scene.attachChild(surLevels.get(i));
				scene.registerTouchArea(surLevels.get(i));				
			}
			this.surLevels = surLevels;
		}
		
		if(subLevels == null) {	
			
			this.subLevels = new ArrayList<Level>();
		} else {				
			for(int i = 0; i < subLevels.size(); i++){
				subLevels.get(i).setPosition(this.posX, this.posY + ((i + 1) * 32.0f));
				scene.attachChild(subLevels.get(i));
				scene.registerTouchArea(subLevels.get(i));
			}			
			this.subLevels = subLevels;
		}
		
		surButton = new LevelAddHandler(this.posX, this.posY -
				(32.0f * this.surLevels.size()), this.surLevels, false, this.scene, level, up, upMin, dw);
		
		subButton = new LevelAddHandler(this.posX, this.posY  +
				(32.0f * (this.subLevels.size() +1)), this.subLevels, true, this.scene, level, down, downMin, dw);
		
		ground = new Rectangle((posX-32)-100, (posY+32)-150, 96, 5);
		
		scene.attachChild(ground);
		
		scene.attachChild(surButton);
		scene.registerTouchArea(surButton);
		scene.attachChild(subButton);
		scene.registerTouchArea(subButton);
		
		// TODO hier
	}
	
	public void attachLevel() {
		
	}
}
